package com.springboot.controller;

import com.springboot.model.bo.BVirtualWalletBO;
import com.springboot.model.po.BVirtualWalletPO;
import com.springboot.model.vo.BVirtualWalletVO;
import com.springboot.service.BVirtualWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope	//监听动态刷新
@RestController
@RequestMapping("/bVirtualWallets")
public class BVirtualWalletController {
    @Autowired
    private BVirtualWalletService bVirtualWalletService;

    @GetMapping("/{businessId}")
    public ResponseEntity getVirtualWalletByBusinessId(@PathVariable Integer businessId){
    	BVirtualWalletBO bbo = bVirtualWalletService.getVirtualWalletByBusinessId(businessId);
    	if(bbo == null) {
    		return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Wrong businessId!");
    	}else {
    		BVirtualWalletBO bvo = new BVirtualWalletBO();
    		bvo.setBalance(bbo.getBalance());
    		bvo.setBusinessId(bbo.getBusinessId());
    		bvo.setWalletId(bbo.getWalletId());
    		return ResponseEntity.ok(bvo);
    	}
    }

}
